﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Web.Configuration;
using Evaluation3.data;

public partial class WebUserControl_Sua_ChiTietThongTinl : System.Web.UI.UserControl
{
    Evaluation3.data.ChiTietThongTin chiTietThongTin;
    DataRow dr;
    OleDbConnection myConnection;
    protected void Page_Load(object sender, EventArgs e)
    {


        String connectinString = WebConfigurationManager.ConnectionStrings["Evaluation"].ConnectionString;
         myConnection = new OleDbConnection(connectinString);
        String strMaChiTietThongTin = Request.Params["MaChiTietThongTin"].ToString();
        txtMaChiTietThongTin.Text = strMaChiTietThongTin;
        try
        {
            myConnection.Open();
            chiTietThongTin = new Evaluation3.data.ChiTietThongTin();
            chiTietThongTin.ActiveConnection = myConnection;
            chiTietThongTin.SelectCondition = "MaChiTietThongTin=" + strMaChiTietThongTin;
            chiTietThongTin.LoadData();
            dr = chiTietThongTin.Rows[0];
        }
        catch (Exception err)
        {
            Console.WriteLine(err.Message);
        }
        finally
        {
            myConnection.Close();
        }
        if (!this.IsPostBack)
        {
            try
            {
                txtMaChiTietThongTin.Text = dr["MaChiTietThongTin"].ToString();
                txtTenChiTietThongTin.Text = dr["TenChiTietThongTin"].ToString();
                txtTenSanPham.Text = dr["TenSanPham"].ToString();
                txtTenHoiDong.Text = dr["TenHoiDong"].ToString();
                txtAlphaI.Text = dr["AlphaI"].ToString();
                txtGhiChu.Text = dr["GhiChu"].ToString();
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }
            finally
            {
                myConnection.Close();
            }
        }
    }
    protected void bntSave_Click(object sender, EventArgs e)
    {
        if (txtTenChiTietThongTin.Text == null || txtTenChiTietThongTin.Text.Trim().Length < 1)
        {
            lblTenChiTietThongTin.Text = "* Tên chi tiết thông tin không được để trống!";
            lblTenChiTietThongTin.Visible = true;
            txtTenChiTietThongTin.Focus();
            return;
        }
        else
        {
            lblTenChiTietThongTin.Visible = false  ;
        }
        if (txtAlphaI.Text != null)
        {
            try
            {
                double I = 0;
                I = Convert.ToDouble(txtAlphaI.Text);
                if (I < 0 || I > 1)
                {
                    lblAlphaI.Text = "* Điểm Alpha I phải trong khoảng từ 0 đến 1!";
                    lblAlphaI.Visible = true;
                    txtAlphaI.Focus();
                    return;
                }
                else
                { 
                    lblAlphaI.Visible = false;
                }
            }
            catch (Exception eConvert)
            {
                lblAlphaI.Text = "* Điểm Alpha I phải là kiểu số!";
                lblAlphaI.Visible = true;
                txtAlphaI.Focus();
                Console.WriteLine(eConvert.Message);
                return;

            }

        }
        else if (txtAlphaI.Text == null)
        {
            lblAlphaI.Text = "* Điểm Alpha I không được để trống!";
            lblAlphaI.Visible = true;
            txtAlphaI.Focus();
            return;
        }
        else
        {
            lblAlphaI.Visible = false;
        }
        //dr["MaChiTietThongTin"] = txtMaChiTietThongTin.Text;
        dr["TenChiTietThongTin"]=txtTenChiTietThongTin.Text ;
        dr["AlphaI"]=txtAlphaI.Text;
        dr["GhiChu"] = txtGhiChu.Text;
        chiTietThongTin.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
    }
    protected void bntCancel_Click(object sender, EventArgs e)
    {
        lblAlphaI.Text = dr["TenChiTietThongTin"].ToString();
        lblAlphaI.Visible = true;
    }
}
